package com.cskaoyan.controller.backstagecontroller;

import com.cskaoyan.bean.vo.*;
import com.cskaoyan.bean.wxvo.WxConfigVo;
import com.cskaoyan.service.ConfigManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("admin/config")
public class ConfigController {


    @Autowired
    ConfigManagementService configManagementService;

    /**
     * 商场信息回显
     * @return
     */
    @GetMapping("mall")
    public BaseRespVo getConfig() {
        MallConfigVo mallConfigVo = configManagementService.getConfig ();
        return BaseRespVo.ok (mallConfigVo);
    }

    /**
     * 商场信息修改
     * @param map
     * @return
     */
    @PostMapping("mall")
    public BaseRespVo setConfig(@RequestBody Map<String, String> map) {
        int affectRows= configManagementService.setConfig (map);
        System.out.println (affectRows);
        return BaseRespVo.ok ();
    }

    /**
     * 运费配置信息回显
     * @return
     */
    @GetMapping("express")
    public BaseRespVo getExpress(){
        ExpressConfigVo expressConfig = configManagementService.getExpressConfig ();
        return BaseRespVo.ok (expressConfig);
    }


    /**
     * 运费配置信息修改
     */
    @PostMapping("express")
    public BaseRespVo expressConfig(@RequestBody Map<String,String> map) {
        int affectRows = configManagementService.setExpressConfig (map);
        System.out.println (affectRows);
        return BaseRespVo.ok ();
    }

    /**
     * 订单配置信息回显
     * @return
     */
    @GetMapping("order")
    public BaseRespVo getOrderConfig(){
        OrderConfigVo orderConfig = configManagementService.getOrderConfig ();
        return BaseRespVo.ok (orderConfig);
    }

    /**
     * 订单配置修改
     * @param map
     * @return
     */
    @PostMapping("order")
    public BaseRespVo setOrderConfig(@RequestBody Map<String,String> map){
        int affectRows = configManagementService.setOrderConfig (map);
        return BaseRespVo.ok ();
    }

    /**
     * 微信小程序配置信息回显
     * @return
     */
    @GetMapping("wx")
    public BaseRespVo getWxConfig(){
        WxConfigVo wxConfig = configManagementService.getWxConfig ();
        return BaseRespVo.ok (wxConfig);
    }

    /**
     * 微信小程序配置信息修改
     * @param map
     * @return
     */
    @PostMapping("wx")
    public BaseRespVo setWxConfig(@RequestBody Map<String,String> map){

        int affectRows = configManagementService.setWxConfig (map);
        return BaseRespVo.ok ();
    }

}
